package com.cn.springcloudwechat.serviceImpl;

import com.cn.springcloudwechat.common.utils.ErrorUtil;
import com.cn.springcloudwechat.mapper.mapper.YmUserCollectionMapper;
import com.cn.springcloudwechat.model.YmUserCollection;
import com.cn.springcloudwechat.service.YmUserCollectionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

@Service
public class YmUserCollectionServiceImpl implements YmUserCollectionService {


    @Autowired
    private YmUserCollectionMapper ymUserCollectionMapper;

    @Override
    public List<Map<String,Object>> getCourse(Long userId) {
        Assert.notNull(userId,String.format(ErrorUtil.PARAMETER_NULL, "userId"));
        List<Map<String,Object>> list=ymUserCollectionMapper.getCourse(userId);
        return list;
    }

    @Override
    public List<Map<String,Object>> getGraphic(Long userId) {
        Assert.notNull(userId,String.format(ErrorUtil.PARAMETER_NULL, "userId"));
        List<Map<String,Object>> list=ymUserCollectionMapper.getGraphic(userId);
        return list;
    }

    @Override
    public Integer insertCollection(String collectionType, Long collectionTypeId, Long userId) {
        Assert.notNull(collectionType,String.format(ErrorUtil.PARAMETER_NULL, "collectionType"));
        Assert.notNull(collectionTypeId,String.format(ErrorUtil.PARAMETER_NULL, "collectionTypeId"));
        Assert.notNull(userId,String.format(ErrorUtil.PARAMETER_NULL, "userId"));
        Integer  integer = ymUserCollectionMapper.insertCollection(collectionType,collectionTypeId,userId);
        return integer;
    }



    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteCollectionState(Long collectionTypeId,Long userId) {
        Assert.notNull(collectionTypeId,String.format(ErrorUtil.PARAMETER_NULL, "collectionTypeId"));
        Assert.notNull(userId,String.format(ErrorUtil.PARAMETER_NULL, "userId"));
        Integer integer=ymUserCollectionMapper.deleteCollectionState(collectionTypeId,userId);
        return integer;
    }

    @Override
    public Integer getRepeat(Long collectionTypeId,Long userId) {
        Assert.notNull(collectionTypeId,String.format(ErrorUtil.PARAMETER_NULL, "collectionTypeId"));
        Assert.notNull(userId,String.format(ErrorUtil.PARAMETER_NULL, "userId"));
        Integer integer=ymUserCollectionMapper.getRepeat(collectionTypeId,userId);
        return integer;
    }


}
